﻿
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Models.Common;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections;
using ServiceWeb.DBGateway;
using Models.JsonResultModel;
using NuGet.Versioning;
using SQLitePCL;
using UtilsBase;
using UtilsORM;
using UtilsORM.MySqlData;
using GatewayServer.Common;

namespace GatewayServer.Controllers
{
    public class DeviceLinkageLogController : BaseMagerController
    {
        EFYihongIotContext ef = new EFYihongIotContext();
        // GET: Mager_Department
        public IActionResult list(IFormCollection FC, HttpReqModel httpRequest, int PageIndex = 1, int PageSize = 15, string type = "1")
        {

            List<SugarParameter> sugarParameters = new List<SugarParameter>();
            int totalRecord = 0;
            string sqlwhere = " ";


            if (!string.IsNullOrEmpty(httpRequest.guid))
            {
                sqlwhere = sqlwhere + "  and l_l_guid = @guid ";
                sugarParameters.Add(new SugarParameter("guid", httpRequest.guid));

            }
            if (!string.IsNullOrEmpty(FC["hid_pageIndex"]))
            {
                PageIndex = int.Parse(FC["hid_pageIndex"].ToString());

            }

            string sql = "select  d_name,lc_key,lc_value,l.*,lg.l_title from   iot_device_linkage_condition_log l inner join iot_device_linkage lg on lg.l_guid=l.l_l_guid inner join iot_device_linkage_condition on lc_guid=l_lc_guid inner join iot_device on d_guid=lc_d_guid where 1= 1  " + sqlwhere;
            DataTable dt = MySqlYihongIot.getPageDataTable(PageIndex, PageSize, sql, sugarParameters, "l_id desc", ref totalRecord);

            ViewData["DataList"] = dt;

            ViewBag.PageSize = PageSize;
            ViewBag.RecordCount = totalRecord;//总条数
            ViewBag.PageCount = totalRecord % PageSize == 0 ? totalRecord / PageSize : totalRecord / PageSize + 1;//分的页数
            ViewBag.PageIndex = PageIndex;//当前页码
            return View(httpRequest);
        }
    }
}